package com.fc.remoting;

import com.fc.remoting.handler.HttpServiceHandler;
import com.fc.remoting.handler.ChannelManagerHandler;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;

public class HttpChannelInitializer extends ChannelInitializer<SocketChannel>{

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ch.pipeline().addLast(new ChannelManagerHandler());
		// server端发送的是httpResponse，所以要使用HttpResponseEncoder进行编码
		ch.pipeline().addLast(new HttpResponseEncoder());
		// server端接收到的是httpRequest，所以要使用HttpRequestDecoder进行解码
		ch.pipeline().addLast(new HttpRequestDecoder());
		ch.pipeline().addLast(new HttpServiceHandler());
	}
}
